#include<string>
#include<vector>
#include<array>
#include<unordered_map>
#include<algorithm>
#include<limits>
#include <stack>
#include<iostream>
#include<sstream>
#include<deque>
#include <queue>
#define MOD 1000000007
class Solution {
public:
    std::vector<int> movesToStamp(std::string stamp, std::string target) {
        int sl = stamp.length();
        int tl = target.length();
        std::vector<std::vector<int>> tu(tl);
        std::queue<int> q;
        std::vector<int> du(tl-sl+1,sl);
        for (int i=0;i<tl-sl+1;i++)
        {
            for (int j=0;j<sl;j++)
            {
                if (stamp[j] == target[i+j])
                {
                    du[i]--; 
                    if (du[i] == 0)
                    {
                        q.push(i);
                    }
                }else
                {
                    tu[i+j].push_back(i);
                }
            }
        }
        std::vector<int> res;
        int size = 0;
        std::vector<bool> visited(tl,false);
        while (!q.empty())
        {
            int index  = q.front();
            q.pop();
            res.push_back(index);
            size++;
            for (int i=0;i<sl;i++)
            {
                if (!visited[index+i])
                {
                    visited[index+i] = true;
                    for (const int a: tu[index+i])
                    {
                        du[a] --;
                        if (du[a] == 0)
                        {
                            q.push(a);
                        }
                  
                    }
                }
               
            }
        }
        if (size != tl-sl+1)
        {
            res.clear();
        }
        reverseArray(res,size);
        return res;
    }
    void reverseArray(std::vector<int>& path, int size) {
        for (int i = 0, j = size - 1; i < j; i++, j--) {
            int tmp = path[i];
            path[i] = path[j];
            path[j] = tmp;
        }
    }
};
